package com.lsq.tucao.express.controller;

import com.lsq.tucao.express.bean.po.HeartDiscuss;
import com.lsq.tucao.express.response.JsonResult;
import com.lsq.tucao.express.service.HeartDiscussService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/heart-discuss")
public class HeartDiscussController {

    @Autowired
    private HeartDiscussService heartDiscussService;

    /**
     * @author lsq
     * @description 根据鸡汤id分页获取其评论数据
     * @param current 页码
     * @param size 每页条数
     * @param heartId 鸡汤id
     * @return com.lsq.tucao.express.response.JsonResult
     * @create 2021/4/20 23:29
     */
    @GetMapping("/page")
    public JsonResult getPageDiscussByHeartId(@RequestParam(required = false,defaultValue = "1") Integer current,
                                              @RequestParam(required = false,defaultValue = "5") Integer size,
                                              @RequestParam Long heartId){
        log.debug("current:{}",current);
        log.debug("size:{}",size);
        log.debug("heartId:{}",heartId);

        return heartDiscussService.getPageDiscussByHeartId(current, size, heartId);
    }

    /**
     * @author lsq
     * @description 发布鸡汤评论
     * @param heartDiscuss 鸡汤评论实体类
     * @return com.lsq.tucao.express.response.JsonResult
     * @create 2021/4/20 23:42
     */
    @PostMapping
    public JsonResult addDiscuss(@RequestBody HeartDiscuss heartDiscuss){
        log.debug("heartDiscuss:{}",heartDiscuss);

        return heartDiscussService.addDiscuss(heartDiscuss);
    }

}
